<script setup>
import { ref } from "vue";
import _api from "@/common/api/role";
import { ElMessage } from "element-plus";
const emit = defineEmits(["added"]);

const isShow = ref(false);
const form = ref({
  name: "",
  age: "",
});

const showDialog = () => {
  form.value = {};
  isShow.value = true;
};

const addRole = async () => {
  try {
    await _api.addAsyncList(form.value);
    emit("added", {});
    ElMessage({
      message: "新增成功",
      grouping: true,
      type: "success",
    });
  } catch (error) {
    console.log(error);
  } finally {
    isShow.value = false;
  }
};

defineExpose({
  showDialog,
});
</script>

<template>
  <el-dialog v-model="isShow" title="新增角色" width="500">
    <div>
      <el-form :model="form" label-width="80px">
        <el-form-item label="角色名">
          <el-input v-model="form.name" placeholder="请输入角色名" />
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="form.age" placeholder="请输年龄" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="isShow = false">取消</el-button>
        <el-button type="primary" @click="addRole"> 确认 </el-button>
      </div>
    </template>
  </el-dialog>
</template>



<style></style>